package com.yh.dao;

import com.yh.javabean.Users;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface UsersDao {
    Users selectByUserName(String username);

    //查询用户列表
    @Select("select * from users")
    //关联查询，一对多 用户列表显示角色
    @Results(id = "u_r",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "role",one=@One(select = "com.yh.dao.RoleDao.selectByUid",fetchType = FetchType.EAGER))
    }
    )
    List<Users> selectAll();

    int insertUsers(Users users);

    @Select("select * from users where id=#{id}")
    @ResultMap("u_r")
    Users selectById(int id);

    //删除用户
    @Delete("delete from users where id=#{id}")
    int deleteById(int id);

    //修改用户
    @Update("update users set email=#{email},username=#{username},password=#{password},phoneNum=#{phoneNum},status=#{status} where id=#{id}")
    int updateUsers(Users users);
}
